<?php  
$pPageIsPublic = false;
include '../_common.php';
	
$_SESSION["m1"]="menu";
$_SESSION["m2"]='combo-list';
$objName="TipoCombo"; $objUrl="tipocombo"; $objTitle="Tipo de Combo";

$pTitle  = "Nueva {$objTitle}";
$pButton = 'Guardar';
$action  = 'add';
$id 	 = intval($_REQUEST['id']);
$seo	 = NULL;


$objLoad = new TipoCombo();
$objLoad ->setUid($id);
if ($objLoad ->load()) {
	$pTitle  = "Editar {$objTitle}";
	$pButton = 'Actualizar';
	$action  = 'edit';
}

if (isset($_POST['submit'])) {
	$objLoad ->setAuto($_POST);
	if ($_POST['action'] == 'edit') {
		$objLoad ->getConnection();
		$objLoad ->setUid($id);
		$objLoad ->update();
		Tzn::redirect("{$objUrl}-list.php", "{$objTitle} ha sido actualizado.");
	} elseif ($_POST['action'] == 'add') {
		$objLoad ->add();
		Tzn::redirect("{$objUrl}-list.php", "{$objTitle} ha sido registrado.");
	}
}
?>
<?php include("header.php"); ?>
<?php
$tabs 	= array('combo' => 1);
$selTab = $tabs[$_REQUEST['tab']] ? $tabs[$_REQUEST['tab']] : 0;
?>
<script type="text/javascript">
$(document).ready(function(){
	$('#frmMain').validate();
	$('#content-tabs').tabs({
		disabled :[<?php echo !$objLoad ->isLoaded() ? "1" : "" ?>],
		active : <?php echo $selTab ?>
	});
});
</script>
<?php include("sidebar.php"); ?>
<ul id="subnav" >
	<li ><a class="back" href="<?= $objUrl ?>-list.php" > Atras </a></li>
	<li class="noborder" >
		<a class="add" href="<?= $objUrl ?>-add.php" > Agregar un <?= $objTitle ?> </a>
	</li>
</ul>
<div id="list">
<h2> <?php echo $pTitle;?> </h2>
<div id="content-tabs">
		<ul>
			<li><a href="#fragment-1" ><span>Tipo de Combo</span></a></li>
			<li><a href="#fragment-2"><span>Combos</span></a></li>
		</ul>
		<div id="fragment-1" >
			<form action="" method="post" name = "frmMain" id = "frmMain" >
				<fieldset><legend> Informaci&oacute;n General </legend>
					<table cellpadding="0" cellspacing="0" class="table-form"  >
						<tr>
							<th>T&iacute;tulo: </th>
								<td><?php $objLoad ->qText('titulo', '', 'width:548px', 'class="required"');?></td>
							</tr>
							<tr>
								<th>Estado: </th>
								<td><?php $objLoad ->arrayToSelect($objLoad ->_arrStatus, 'estado', $objLoad ->estado, false, 'width:100px', '');?></td>
							</tr>
					</table>
				</fieldset>
			<div style="margin-top:10px">
					<input type="hidden" name="id" value="<?php echo $id; ?>" />
					<input type="hidden" name="action" value="<?php echo $action; ?>" />
			                <input type="submit" name="submit"  value="<?php echo $pButton; ?>" /> &nbsp; <input type="reset" value="Cancelar" onClick="window.location.href='<?= $objUrl ?>-list.php'" />
			</div>
			</form>
		</div>
		<div id="fragment-2" >
			<fieldset><legend> Listado de combos <?= $objLoad ->isLoaded() ? "en {$objLoad ->titulo}" : "" ?>  </legend>
				<?php 
					Common::hFrmFilterAdmin('Combo', 'Combo', 'combo', "pid={$objLoad ->id}");
					$objChild  = new Combo();
					$objChild ->loadItems(null, "#estado like '". $chkstatus ."%' AND #tipocomboId='". intval($objLoad ->id) ."'");
					echo "<div id='wrap-list'>" . Common::hSimpleGrid('Combo', 'Combo', 'combo', $objChild, false) . '</div>';
				?>
			</fieldset>
		</div>
</div>
</div>
<?php include("footer.php"); ?>